//
//  RegAndLoginViewController.m
//  糗事百科
//
//  Created by lanouhn on 15/5/28.
//  Copyright (c) 2015年 暴走. All rights reserved.
//

#import "RegAndLoginViewController.h"

#define kSCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define kSCREENHEIGHT [UIScreen mainScreen].bounds.size.height

@interface RegAndLoginViewController ()     //登陆界面图

@property (nonatomic, retain) UILabel *ralLabel;
@property (nonatomic, retain) UILabel *qbLoginLabel;
@property (nonatomic, retain) UILabel *forgetLabel;
@property (nonatomic, retain) UIButton *qqAndWeibo;
@property (nonatomic, retain) UITextField *textBox;
@property (nonatomic, retain) UIButton *loginButton;

@end

@implementation RegAndLoginViewController

- (void)dealloc {
    [_ralLabel release];
    [_qbLoginLabel release];
    [_forgetLabel release];
    [_qqAndWeibo release];
    [_loginButton release];
    [_textBox release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:238.0 / 255.0 green:239.0 / 255.0 blue:240 / 255.0 alpha:1.0];
    self.navigationItem.title = @"登陆 / 注册";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor]}];     //通过属性设置标题颜色
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 38, 20);
    [button setTitle:@"取消" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];     //设置导航条左边按钮
    [button addTarget:self action:@selector(handleCancelAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.ralLabel];
    [self.view addSubview:self.qqAndWeibo];
    [self.view addSubview:self.qbLoginLabel];
    [self.view addSubview:self.textBox];
    [self.view addSubview:self.loginButton];
    [self.view addSubview:self.forgetLabel];
}

- (UILabel *)ralLabel {
    if (!_ralLabel) {
        self.ralLabel = [[[UILabel alloc]initWithFrame:CGRectMake(10, 100, kSCREENWIDTH, 30)]autorelease];
        _ralLabel.text = @"使用合作账号一键登陆 / 注册";
        _ralLabel.textColor = [UIColor darkGrayColor];
        _ralLabel.font = [UIFont systemFontOfSize:12];
    }
    return _ralLabel;
}

- (UIButton *)qqAndWeibo {
    if (!_qqAndWeibo) {
        NSArray *imageArray = @[@"row_qq", @"row_sina"];
        NSArray *array = @[@"使用QQ登陆", @" 用微博登陆"];
        for (int i = 0; i < array.count; i++) {
            self.qqAndWeibo = [UIButton buttonWithType:UIButtonTypeCustom];
            _qqAndWeibo.frame = CGRectMake(0, i * 50 + CGRectGetHeight(self.ralLabel.bounds) + 100, self.view.bounds.size.width,50);
            [_qqAndWeibo setTitle:array[i] forState:UIControlStateNormal];
            _qqAndWeibo.titleLabel.font = [UIFont systemFontOfSize:18];
            [_qqAndWeibo setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
            [_qqAndWeibo setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
            _qqAndWeibo.layer.cornerRadius = 5;
            _qqAndWeibo.layer.borderWidth = 0.5;
            _qqAndWeibo.layer.borderColor = [UIColor lightGrayColor].CGColor;
            _qqAndWeibo.backgroundColor = [UIColor whiteColor];
            [self.view addSubview:_qqAndWeibo];
        }
    }
    return _qqAndWeibo;
}

- (UILabel *)qbLoginLabel {
    if (!_qbLoginLabel) {
        self.qbLoginLabel = [[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetHeight(self.qqAndWeibo.bounds) + 190, kSCREENWIDTH/2, 30)]autorelease];
        _qbLoginLabel.text = @"使用暴走账号登陆";
        _qbLoginLabel.textColor = [UIColor darkGrayColor];
        _qbLoginLabel.font = [UIFont systemFontOfSize:12];
    }
    return _qbLoginLabel;
}

- (UIButton *)loginButton {
    if (!_loginButton) {
        self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _loginButton.frame = CGRectMake(25, 420, kSCREENWIDTH - 65, 45);
        _loginButton.backgroundColor = [UIColor orangeColor];
        _loginButton.layer.cornerRadius = 5;    //内切圆半径
        [_loginButton setTitle:@"登 陆" forState:UIControlStateNormal];
    }
    return _loginButton;
}

- (UITextField *)textBox {
    if (!_textBox) {
        NSArray *array = @[@"邮箱 / 暴走昵称", @"密码"];
        for (int i = 0; i < array.count; i++) {
            self.textBox = [[[UITextField alloc]initWithFrame:CGRectMake(0, i * 50 + 270, CGRectGetWidth(self.view.bounds),50)]autorelease];
            _textBox.placeholder = array[i];
            _textBox.borderStyle = UITextBorderStyleRoundedRect;
            _textBox.clearsOnBeginEditing = YES;
            _textBox.font = [UIFont systemFontOfSize:18];
            _textBox.clearButtonMode = UITextFieldViewModeWhileEditing;
            [self.view addSubview:_textBox];
        }
    }
    return _textBox;
}

- (UILabel *)forgetLabel {
    if (!_forgetLabel) {
        self.forgetLabel = [[[UILabel alloc]initWithFrame:CGRectMake(100, kSCREENHEIGHT - 180, kSCREENWIDTH - 200, 30)]autorelease];
        _forgetLabel.text = @"忘记密码?";
        _forgetLabel.textColor = [UIColor darkGrayColor];
        _forgetLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _forgetLabel;
}


- (void)handleCancelAction:(UIBarButtonItem *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];    //解除模态出来的当前视图
    [self.navigationController popViewControllerAnimated:YES];      //回到push视图界面
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
